home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / SPEC Libs / Gestalt.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  16.7 KB  |  542 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Gestalt.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    KTA, KL, ML, GS et al
  9. #
  10. #    Copyright:    © 1993-1995 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    1.0.110>     11/8/95    ML        GestaltOProcessorType - use 'cput' instead         of 'proc'
  19. #    1.0.19+>     11/8/95    ML        GestaltOProcessorType - use 'cput' instead of 'proc'
  20. #    <1.0.19>      4/11/95    KTA        Moved IsPowerPC() to TargetCheck.Lib
  21. #    <1.0.18>      3/8/95    ML        GestaltMachineType() - revise header documentation
  22. #    <1.0.17>    11/30/94    ML        Added Exception Handling
  23. #    <1.0.16>     9/26/94    ML        return LowWordOfAnswer() back to original         form, create
  24. #                                    task GetGestaltValue(), replace         instances of
  25. #                                    LowWordOfAnswer() with GetGestaltValue().
  26. #    <1.0.15>     9/21/94    ML        removed gestres, revise gestalt calls for         VU 2.1
  27. #    <1.0.14>     3/23/94    KTA        Added marks.
  28. #    <1.0.13>     3/15/94    ML        Moved all calls that were non-Gestalt to TargetCheck.lib.
  29. #                                    Removed dependencies on other libs, add support for multiple 
  30. #                                    monitor bit depth.
  31. #    <1.0.12>     12/8/93    KTA        FormLongNumber() - Removed quitting the MathTool - if multiple
  32. #                                    targets are running the tool will not be available.
  33. #     <1.0.9>     12/3/93    KTA        MachineState now returns logical and physical memory in bytes,
  34. #                                    added FormLongNumber() task.
  35. #     <1.0.8>     12/2/93    KTA        Removed globals isOff, IsOn, VirtualMemory, notAvail, etc.
  36. #     <1.0.7>     12/2/93    KTA        Added tasks GestaltSystemArchitecture() and IsPowerPC().  Added
  37. #                                    SystemArchitecture as MachineState() target descriptor.
  38. #     <1.0.6>    11/30/93    ML        Added ReturnMachineName parameter to GestaltMachineType, now
  39. #                                    returns Machine umber by default
  40. #     <1.0.5>      8/9/93    KTA        MachineState() - Updates for new Pheonix data format .
  41. #     <1.0.4>     7/19/93    KTA        InitOnTarget had a syntax error that wasn't caught.
  42. #     <1.0.3>     7/15/93    KTA        Changed the name of some tasks so they wouldn't conflict with
  43. #                                    Gestalt.vulib, changed error checking in InitOnTarget(), removed
  44. #                                    SystemVersion() and MachineName().
  45. #     <1.0.2>      6/8/93    NAGA        unmark tasks that are not published
  46. #        <1.0.1>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  47. #
  48. # ****************************************************************************
  49. #
  50.  
  51. ########################################################################
  52. #                            External libraries 
  53. #=======================================================================
  54. Libraries "ExceptionHandling.lib";    
  55. ##################################################################################
  56. #                        Check32Bit()
  57. #=======================================================================
  58. # Author:        GS
  59. # Description:    This routine will check the state of 32 bit addressing,
  60. #                and returns the value.
  61. # Parameters:    None
  62. # Returns:        Values
  63. #                On        :=  1
  64. #                Off        :=  0
  65. #                not Avail :=  -1
  66. #                GestaltError
  67. #                in the first item a value described above.  The second item is a text 
  68. #                string description of the value.
  69. #=======================================================================
  70. # History:
  71. # ML 11/30/94    Added support for exception handling    
  72. ##################################################################################
  73. Task Check32Bit()
  74. begin
  75.     theResult := GetGestaltValue(_gestalt( 'addr' ));
  76.      
  77.     if (theResult & (1 << 0))
  78.         retVal := {1, "32 bit addressing is ON"};
  79.     
  80.     else if (theResult & (1 << 2))
  81.         retVal := {0, "32 bit addressing is available but turned OFF"};
  82.  
  83.     else if not ((theResult & (1 << 0)) or (theResult & (1 << 1)) or (theResult & (1 << 2)))
  84.         retVal := {-1, "32 bit addressing is not available on this machine"};
  85.  
  86. #        if (gestRes[1]) 
  87. #            retVal := {gestRes[1], "Gestalt Error  (-5550 is gestalt unavailable error)"};
  88.  
  89.     return retVal;
  90. end;
  91.  
  92.  
  93.  
  94. ##################################################################################
  95. #                        CheckVM()
  96. #=======================================================================
  97. # Author:        GS
  98. # Description:    Checks to see if VM is turned on.
  99. #
  100. # Parameters:    None
  101. # Returns:        On   :=  1
  102. #                Off  :=     0
  103. #                not Avail :=  -1
  104. #                GestaltError
  105. # if VM is on gestalt('vm  ') returns a 1
  106. # any other case (not available, not turned on is a 0)
  107. #=======================================================================
  108. # History:
  109. # KTA 12/02/93 Removed isOff, IsOn, VirtualMemory, notAvail, etc.
  110. # ML 11/30/94    Added support for exception handling    
  111. ##################################################################################
  112. TASK CheckVM()
  113. begin
  114.     vmValue := GetGestaltValue(_gestalt( 'vm  ' ));
  115.  
  116.     if (vmValue = 0)
  117.     begin
  118.         theMMU    := GetGestaltValue(_gestalt( 'mmu ' ));
  119.         if(theMMU > 1)
  120.             retVal := {0, "VM is available and OFF"};
  121.         else 
  122.             retVal := {-1, "VM is NOT available on this machine"};
  123.     end;
  124.         
  125.     else if (vmValue & (1 << 0))
  126.         retVal := {1, "VM is ON"};
  127.     
  128. #        errorCode := gestRes[1];    
  129. #        if (errorCode) 
  130. #            retVal := {errorCode, "Gestalt Error  (-5550 is gestalt unavailable error)"};
  131.     
  132.     return retVal;
  133. end;        
  134.  
  135. ##################################################################################
  136. #                        LowWordOfAnswer()
  137. #=======================================================================
  138. # Author:        GS
  139. # Description:    Returns second item of a list.
  140. #
  141. # Parameters:    None
  142. # Returns:        second item of a list
  143. #=======================================================================
  144. # History:
  145. #
  146. ##################################################################################
  147. task LowWordOfAnswer(Answer)
  148. begin
  149.  
  150.     tempVal    := Answer[2];
  151.     retVal  := tempVal[2];
  152.  
  153.     return retVal;
  154. end;
  155.  
  156. ##################################################################################
  157. #                        GetGestaltValue()
  158. #=======================================================================
  159. # Author:        GS
  160. # Description:    Checks a 2 element list, If 2nd element type list, 
  161. #                call LowWordOfAnswer, otherwise return the element.
  162. #
  163. # Parameters:    pAnswer - 2 element list returned from VU's built-in
  164. #                            gestalt task
  165. # Returns:        integer
  166. #=======================================================================
  167. # History:
  168. #    ML    9/26/94    created
  169. ##################################################################################
  170. task GetGestaltValue(pAnswer)
  171. begin
  172.  
  173.     tempVal    := pAnswer[2];
  174.     if (typeof(tempVal) = 'list')
  175.         retVal  := LowWordOfAnswer(pAnswer);
  176.     else
  177.         retVal  := tempVal;
  178.     return retVal;
  179. end;
  180.  
  181.  
  182. ##################################################################################
  183. #                        GestaltLongError()
  184. #=======================================================================
  185. # Author:        GS
  186. # Description:    Will return a longer error response in the form of a string.
  187. #
  188. # Parameters:    None
  189. # Returns:        String with error text
  190. #=======================================================================
  191. # History:
  192. #
  193. ##################################################################################
  194. task GestaltLongError(gestaltAnswer := {0,{0,0}})
  195. begin
  196.     kGestaltNoErr := 0;
  197.     kGestaltUnknownErr := -5550;
  198.     kGestaltUndefSelectorErr := -5551;
  199.  
  200.     gesErr := gestaltAnswer[1];
  201.     if gesErr = kGestaltNoErr
  202.         return "No error";
  203.     else if gesErr = kGestaltUnknownErr
  204.         return "Error: Could not obtain response";
  205.     else if gesErr = kGestaltUndefSelectorErr
  206.         return "Error: Undefined selector";
  207.     else
  208.         return "Error: Unknown error code: {gesErr}";
  209. end;
  210.  
  211.  
  212.  
  213.  
  214.  
  215. ##################################################################################
  216. #                        GestaltFPUType()
  217. #=======================================================================
  218. # Author:        Derived from Virtual User 2.0 Example libraries
  219. # Description:    Returns FPU type.
  220. #
  221. # Parameters:    None
  222. # Returns:        NoFPU
  223. #                68881
  224. #                68882
  225. #                68040
  226. #                unknFPU
  227. #=======================================================================
  228. # History:
  229. #    ML    9/20/94    Funnel gestalt answer through GetGestaltValue task
  230. #                (VU 2.1 support)
  231. # ML 11/30/94    Added support for exception handling    
  232. ##################################################################################
  233. TASK GestaltFPUType()
  234. begin
  235.     gesAns := _Gestalt('fpu ');
  236.     gesErr := gesAns[1];
  237.     if (not gesErr)
  238.     begin
  239.         fpuAns := GetGestaltValue(gesAns);
  240.         if fpuAns = 0
  241.             return "NoFPU";
  242.         else if fpuAns = 1
  243.             return "68881";
  244.         else if fpuAns = 2
  245.             return "68882";
  246.         else if fpuAns = 3
  247.             return "68040FPU";
  248.         else
  249.             return "unknFPU";
  250.     end;
  251.     else
  252.         return GestaltLongError(gesAns);
  253. end;
  254.  
  255.  
  256.  
  257. ##################################################################################
  258. #                        GestaltMachineType()
  259. #=======================================================================
  260. # Author:        Derived from Virtual User 2.0 Example libraries
  261. # Description:    Checks machine being tested and returns string with Machine Type.
  262. #
  263. # Parameters:    0 - return machine number
  264. #                1 - return machine name
  265. # Returns:        String with Machine Name or integer with machine number
  266. #                (See list below)
  267. #=======================================================================
  268. # History:
  269. #    ML    11/30/93    Added ReturnMachineName parameter, now returns Machine
  270. #                    number by default
  271. #    ML    9/20/94    Funnel gestalt answer through GetGestaltValue task
  272. #                (VU 2.1 support)
  273. # ML 11/30/94    Added support for exception handling    
  274. ##################################################################################
  275. TASK GestaltMachineType(ReturnMachineName := 0)
  276. begin
  277.     gesAns := _Gestalt('mach');
  278.     gesErr := gesAns[1];
  279.     if (not gesErr)
  280.     begin
  281.         machAns := GetGestaltValue(gesAns);
  282.         if (ReturnMachineName)
  283.         begin
  284.             if machAns = 1
  285.                 return "Classic";
  286.             else if machAns = 2
  287.                 return "MacXL";
  288.             else if machAns = 3
  289.                 return "Mac512KE";
  290.             else if machAns = 4
  291.                 return "MacPlus";
  292.             else if machAns = 5
  293.                 return "MacSE";
  294.             else if machAns = 6
  295.                 return "MacII";
  296.             else if machAns = 7
  297.                 return "MacIIx";
  298.             else if machAns = 8
  299.                 return "MacIIcx";
  300.             else if machAns = 9
  301.                 return "MacSE030";
  302.             else if machAns = 10
  303.                 return "Portable";
  304.             else if machAns = 11
  305.                 return "MacIIci";
  306.             else if machAns = 13
  307.                 return "MacIIfx";
  308.             else if machAns = 17
  309.                 return "MacClassic";
  310.             else if machAns = 18
  311.                 return "MacIIsi";
  312.             else if machAns = 19
  313.                 return "MacLC";
  314.             else if machAns = 20
  315.                 return "Quadra900";
  316.             else if machAns = 21
  317.                 return "Powerbook170";
  318.             else if machAns = 22
  319.                 return "Quadra700";
  320.             else if machAns = 23
  321.                 return "ClassicII";
  322.             else if machAns = 24
  323.                 return "PowerBook100";
  324.             else if machAns = 25
  325.                 return "PowerBook140";
  326.             else if machAns = 26
  327.                 return "Quadra 950";
  328.             else
  329.                 return MachAns;
  330.         end; # if ReturnMachineName
  331.         else
  332.             return MachAns;
  333.     end; # if (not gesErr)
  334.     else
  335.         return GestaltLongError(gesAns);
  336. end;
  337.  
  338.  
  339. ##################################################################################
  340. #                        GestaltProcessorType()
  341. #=======================================================================
  342. # Author:        Derived from Virtual User 2.0 Example libraries
  343. # Description:    Returns the processor running on the test machine
  344. #
  345. # Parameters:    None
  346. # Returns:        68000
  347. #                68010
  348. #                68020
  349. #                68030
  350. #                68040
  351. #=======================================================================
  352. # History:
  353. #    ML    9/20/94    Funnel gestalt answer through GetGestaltValue task
  354. #                (VU 2.1 support)
  355. # ML 11/30/94    Added support for exception handling
  356. # ML 11/08/95    use 'cput' instead of 'proc'
  357. ##################################################################################
  358. TASK GestaltProcessorType()
  359. begin
  360.     gesAns := _Gestalt('cput');
  361.     gesErr := gesAns[1];
  362.     if (not gesErr)
  363.     begin
  364.         procAns := gesAns[2];
  365.         if procAns = 0
  366.             return "68000";
  367.         else if procAns = 1
  368.             return "68010";
  369.         else if procAns = 2
  370.             return "68020";
  371.         else if procAns = 3
  372.             return "68030";
  373.         else if procAns = 4
  374.             return "68040";
  375.         else if procAns = 257
  376.             return "601";
  377.         else if procAns = 259   # unable to fully test - no PowerSurge machines available
  378.             return "603";
  379.         else 
  380.             return "unknProc";
  381.     end;
  382.     else
  383.         return GestaltLongError(gesAns);
  384. end;
  385.  
  386.  
  387.  
  388. ##################################################################################
  389. #                        GestaltMMUType()
  390. #=======================================================================
  391. # Author:        Derived from Virtual User 2.0 Example libraries
  392. # Description:    Will return the memory management unit type found operating on the target.
  393. #
  394. #
  395. # Parameters:    None
  396. # Returns:        NoMMU
  397. #                AMU
  398. #                68851
  399. #                68030MMU
  400. #                68040MMU
  401. #                unknMMUType
  402. #=======================================================================
  403. # History:
  404. #    ML    9/20/94    Funnel gestalt answer through GetGestaltValue task
  405. #                (VU 2.1 support)
  406. # ML 11/30/94    Added support for exception handling    
  407. ##################################################################################
  408. TASK GestaltMMUType()
  409. begin
  410.     gesAns := _Gestalt('mmu ');
  411.     gesErr := gesAns[1];
  412.     if (not gesErr)
  413.     begin
  414.         mmuAns := GetGestaltValue(gesAns);
  415.         if mmuAns = 0
  416.             return "NoMMU";
  417.         else if mmuAns = 1
  418.             return "AMU";
  419.         else if mmuAns = 2
  420.             return "68851";
  421.         else if mmuAns = 3
  422.             return "68030MMU";
  423.         else if mmuAns = 4
  424.             return "68040MMU";
  425.         else
  426.             return "unknMMUType";
  427.     end;
  428.     else
  429.         return GestaltLongError(gesAns);
  430. end;
  431.  
  432.  
  433. ##################################################################################
  434. #                        GestaltLogicalRAMSize()
  435. #=======================================================================
  436. # Author:        Derived from Virtual User 2.0 Example libraries
  437. # Description:    Will return the amount of logical RAM located in a machine.
  438. #                (VM+RM)  
  439. #
  440. #
  441. # Parameters:    None
  442. # Returns:        an integer in megabytes.
  443. #=======================================================================
  444. # History:
  445. #    ML    9/20/94    Add VU 2.1 support
  446. # ML 11/30/94    Added support for exception handling    
  447. ##################################################################################
  448. TASK GestaltLogicalRAMSize()
  449. begin
  450.     gesAns := _Gestalt('lram');
  451.     gesErr := gesAns[1];
  452.     if (not gesErr)
  453.     begin
  454.         if (typeof(gesAns[2]) = 'list') # VU 2.0x
  455.         begin
  456.             theHiWord := gesAns[2][1];
  457.             # Gestalt apparently has a problem reporting the full 8MB of physical memory
  458.             # on machines with no virtual memory enabled.  This will compensate.
  459.             return (theHiWord + 1) / 16;
  460.         end; # if (typeof(gesAns[2]) = 'list')
  461.         else # VU 2.1x
  462.             return (gesAns[2]);
  463.     end;
  464.     else
  465.         return GestaltLongError(gesAns);
  466. end;
  467.  
  468.  
  469. ##################################################################################
  470. #                        GestaltPhysicalRAMSize()
  471. #=======================================================================
  472. # Author:        Derived from Virtual User 2.0 Example libraries
  473. # Description:    Will return the amount of physical RAM located in a machine.
  474. #
  475. #
  476. # Parameters:    None
  477. # Returns:        an integer in megabytes.
  478. #=======================================================================
  479. # History:
  480. #    ML    9/20/94    Add VU 2.1 support
  481. # ML 11/30/94    Added support for exception handling    
  482. ##################################################################################
  483. TASK GestaltPhysicalRAMSize()
  484. begin
  485.     gesAns := _Gestalt('ram ');
  486.     gesErr := gesAns[1];
  487.     if (not gesErr)
  488.     begin
  489.         if (typeof(gesAns[2]) = 'list') # VU 2.0x
  490.         begin
  491.             theHiWord := gesAns[2][1];
  492.             # Gestalt apparently has a problem reporting the full 8MB of physical memory
  493.             # on machines with no virtual memory enabled.  This will compensate.
  494.             return (theHiWord + 1) / 16;
  495.         end; # if (typeof(gesAns[2]) = 'list')
  496.         else # VU 2.1x
  497.             return (gesAns[2]);
  498.     end;
  499.     else
  500.         return GestaltLongError(gesAns);
  501. end;
  502.  
  503.  
  504. #########################################################################
  505. #                 GestaltSystemArchitecture()
  506. #=======================================================================
  507. # Author:          KTA
  508. # Description:    Makes a Gestalt call with selector of 'sysa' to determine if the
  509. #                target system is 68K or PowerPC
  510. # Parameters:    none
  511. # Returns:        0 - Selector not installed (older 68k)
  512. #                1 - Selector installed - target is 68k based not PowerPC
  513. #                2 - Selector installed - target is PowerPC based not 68k
  514. #=======================================================================
  515. # History:
  516. # KTA    12/01/93    Created
  517. #    ML    9/20/94    Add VU 2.1 support
  518. # ML 11/30/94    Added support for exception handling    
  519. ########################################################################
  520. TASK GestaltSystemArchitecture()
  521. begin    
  522.     gesAns := _Gestalt('sysa');
  523.     #println gesAns;
  524.     if(GesAns[1] = -5551)    # Selector not installed (older 68k machine)
  525.         ReturnVal := 0;
  526.     else if (GesAns[1] = 0)
  527.     begin
  528.         SysArchAns := GetGestaltValue(gesAns);
  529.         if( SysArchAns = 1)    # 68k system
  530.             returnVal := 1;
  531.         else if ( SysArchAns = 2)    # PowerPC native system
  532.             returnVal := 2;
  533.         else
  534.             println "returnVal unknown - {SysArchAns}";
  535.     end;
  536.     else
  537.         println " - a unexpected gestalt error occured - {gesAns}";
  538.     
  539.     return(ReturnVal);    
  540. end;
  541.  
  542.